package com.mzj.saas.mservice.house.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.house.service.RentService;
import com.mzj.saas.mservice.house.vo.BacklogRentInfoVO;
import com.mzj.saas.mservice.house.vo.CanRentHouseDataVO;
import com.mzj.saas.mservice.house.vo.CanRentHouseVO;
import com.mzj.saas.mservice.house.vo.WaitingRentRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 配租接口
 */
@Controller
@RequestMapping("/houseRent")
public class RentController {
    @Autowired
    private RentService rentService;

    /**
     * 配租人信息列表
     *
     * @param orgId
     * @param residenceCommunityId
     * @return
     */
    @GetMapping("/findWaitingUser")
    @ResponseBody
    public ResultBean<List<WaitingRentRecordVO>> findWaitingUser(@RequestParam(value = "orgId", required = false) Long orgId,
                                                                 @RequestParam(value = "residenceCommunityId", required = false) String residenceCommunityId,
                                                                 @RequestParam(value = "backlogItemId", required = false) Long backlogItemId) {
        return rentService.findWaitingUser(orgId, residenceCommunityId, backlogItemId);
    }

    /**
     * 可配租房列表
     *
     * @param pageNumber
     * @param pageSize
     * @param id          公租房id
     * @param buildingNum
     * @param unit
     * @param roomNumber
     * @return
     */
    @GetMapping("/canRentHouse")
    @ResponseBody
    public ResultBean<CanRentHouseDataVO<CanRentHouseVO>> canRentHouse(@RequestParam(defaultValue = "0") Integer pageNumber,
                                                                       @RequestParam(defaultValue = "5") Integer pageSize,
                                                                       @RequestParam(value = "id", required = false) String id,
                                                                       @RequestParam(value = "backlogItemId", required = false) Long backlogItemId,
                                                                       @RequestParam(value = "buildingNum", required = false) Long buildingNum,
                                                                       @RequestParam(value = "unit", required = false) Long unit,
                                                                       @RequestParam(value = "roomNumber", required = false) String roomNumber,
                                                                       @RequestParam(value = "matchUserId", required = false) String matchUserId) {
        return rentService.canRentHouse(pageNumber, pageSize, id, backlogItemId, buildingNum, unit, roomNumber, matchUserId);
    }

    /**
     * 配租操作
     *
     * @param recordId
     * @param houseId
     * @param applyId
     * @param matchUserId
     * @return
     */
    @GetMapping("/rent")
    @ResponseBody
    public ResultBean<Object> rent(@RequestHeader String accessToken,
                                   @RequestParam(value = "recordId") Long recordId,
                                   @RequestParam(value = "houseId") String houseId,
                                   @RequestParam(value = "applyId") Long applyId,
                                   @RequestParam(value = "matchUserId") String matchUserId,
                                   @RequestParam(value = "applyCode", required = false) String applyCode) {
        return rentService.rent(accessToken, recordId, houseId, applyId, matchUserId, applyCode);
    }

    /**
     * 配租信息-待办事项
     *
     * @param accessToken
     * @param backlogItemId
     * @return
     */
    @GetMapping("/backlogRentInfo")
    @ResponseBody
    public ResultBean<BacklogRentInfoVO> backlogRentInfo(@RequestHeader String accessToken,
                                                         @RequestParam(value = "backlogItemId") Long backlogItemId) {
        return rentService.backlogRentInfo(accessToken, backlogItemId);
    }


}
